<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>SWF 播放器</title>
  <script src="https://unpkg.com/@ruffle-rs/ruffle"></script>
  <script>
    window.RufflePlayer = window.RufflePlayer || {};
    window.RufflePlayer.config = { scale: 'fit', letterbox: 'off', quality: 'best' };
    function getParam(name) {
      const url = new URL(window.location.href);
      const val = url.searchParams.get(name);
      return val ? decodeURIComponent(val) : '';
    }
    async function swfExists(url) {
      try {
        const res = await fetch(url, { method: 'HEAD' });
        return res.ok;
      } catch (e) { return false; }
    }
    document.addEventListener('DOMContentLoaded', async () => {
      const file = getParam('file');
      const bg = getParam('bg');
      const v = getParam('v');
      document.body.style.background = bg || '#111';
      const swfPath = file && file.includes('/') ? file : `../swf/${file}`;
      const swfUrl = `${swfPath}${v ? `?v=${v}` : ''}`;
      const exists = file && await swfExists(swfUrl);
      if (!exists) {
        const msg = document.getElementById('missing-msg');
        msg.innerText = `未找到对应的SWF文件：${file || '未提供文件名'}`;
        msg.style.display = 'flex';
        return;
      }
      const r = window.RufflePlayer?.newest();
      if (!r) return;
      const player = r.createPlayer();
      player.style.width = '100%';
      player.style.height = '100%';
      document.getElementById('player').appendChild(player);
      player.load(swfUrl);
    });
  </script>
  <style>
    html, body { height: 100%; }
    body { margin: 0; }
    .wrap { height: 100vh; width: 100vw; }
    .game { position: fixed; inset: 0; }
    #player, ruffle-embed, ruffle-player { width: 100%; height: 100%; }
    .missing { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; color: #fff; font-size: 18px; background: rgba(0,0,0,0.6); }
  </style>
</head>
<body>
  <div class="wrap">
    <div class="game"><div id="player"></div></div>
    <div id="missing-msg" class="missing"></div>
  </div>
</body>
</html>